﻿var AJAXController = {
    url: "/AJAXController/AJAXResponseBuilder.aspx",
    ajax_calling: "",
    hasFirebug: function () { return ("console" in window && "firebug" in window.console) },
    AR: function (callto, params, updateElementId) {
        AJAXController.ARC(callto, params, updateElementId, null);
    },

    ARC: function (callto, params, updateElementId, callback) {
        if (callto != "") {
            if ($("#divSystemWorking")) $("#divSystemWorking").show();
            AJAXController.ajax_calling = callto;
            var call = { callname: callto };
            if (!params) params = {};
            if (params && params == "") params = {};
            $.extend(params, call);
            $.ajax({
                url: this.url,
                type: "POST",
                data: (params),
                dataType: "html",
                success: function (response) {
                    if (updateElementId != "" && $(updateElementId))
                        $(updateElementId).html(response);
                    if (callback && (typeof callback === "function"))
                        callback(response);
                    if ($("#divSystemWorking")) $("#divSystemWorking").hide();

                },
                error: function (response) {
                    if (AJAXController.hasFirebug())
                        console.log("[error]AJAXController: callname:" + callto + " --> " + response);
                }
            });
        } else {
            if (AJAXController.hasFirebug())
                console.log("[error]AJAXController: no callname");
        }
    }
}
